package cn.it.hbtt.Servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.it.hbtt.dao.BaseDAO;
import cn.it.hbtt.entity.News;

@WebServlet("/view_source")
public class view_sourceServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		response.setContentType("text/html;charset=UTF-8");
		request.setCharacterEncoding("UTF-8");
		PrintWriter out=response.getWriter();
		String name=request.getParameter("name");
		String pwd=request.getParameter("password");
		
		try {
			BaseDAO base=new BaseDAO();
			Connection conn=base.getConnection();
			
			Statement stm = conn.createStatement();
			ResultSet rs = stm.executeQuery("select title,createTime from easybuy_news limit 0,10");
			List<News>  list=new ArrayList<News>();
			while (rs.next()==true) {
				News n = new News();
				//n.setId(rs.getInt("id"));
				n.setTitle(rs.getString("title"));
				//n.setContent(rs.getString("content"));
				n.setCreateTime(rs.getString("createTime"));
				list.add(n);
				
			}
			for(Object li:list) {
				out.print(li);
			}
		
		}  catch (SQLException e) {
			e.printStackTrace();
		}
	
		
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		doGet(request, response);
	}

}
